import java.io.*;

public class minimc {
	
	static String is = "";

	static void timer(long x) { 
		long timeout = x;
	 
		while (true) {
		
			try {
				Thread.sleep(timeout);
				break;
			}
			catch (InterruptedException ie) {
				ie.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		
		System.out.println("Which model are you checking (1 or 2):");
		BufferedReader mbr = new BufferedReader(new InputStreamReader(System.in));
		String ln;
		try {
			ln = mbr.readLine().trim();
			
			if (ln.equals("1")) {
				System.out.println("You chose Model 1");
				System.out.println("Enter the Initial State for Model 1 (1,2,3,4,5):");
				BufferedReader m2br = new BufferedReader(new InputStreamReader(System.in));
				ln = m2br.readLine().trim();
				is = ln;
				System.out.println("Initial State for Model 1 set to: " + ln);
			} else {
				System.out.println("You chose Model 2");
				System.out.println("Enter the config file path:");
				BufferedReader m2br = new BufferedReader(new InputStreamReader(System.in));
				ln = m2br.readLine().trim();
				is = "2";
				timer(4000);
				System.out.println("Thank you, configuration loaded for the Game of Life!");

			}
			
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
		
		
		String pyParser = "python \"C:\\Users\\Emir\\My Homework\\CSC458\\meh\\propositions\\parser.py\"";

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedReader pbr;

		String line;
		String cmd;
		String formula = "";

		Process p;
		
		// aU[p, eAT[and[q, not[r]]]]
		


		try {
			while(true) {
				System.out.println("Please enter a property or press # to quit:");
				line = br.readLine().trim();
								
				if(line.equals("#")) {
					System.out.println("Goodbye!");
					break;
				}
				cmd = pyParser + " \"" + line + "\"";
				System.out.println(cmd);

				Runtime r = Runtime.getRuntime();
				p = r.exec(cmd);
				pbr = new BufferedReader(new InputStreamReader(p.getInputStream()));
				p.waitFor();
				while (pbr.ready()) {
					formula = pbr.readLine();

					
				}
				p.destroy();
				pbr.close();
				
				
				//parse formula into tree
				//System.out.println(formula.trim());
				BTree tree = new BTree(formula.trim(), true);
				Model m = new Model();
				
				m.createModel1(m);
				m.setInitialState(m, is);
				m.traverse(tree.getRoot(), m.getInitialState());
				
				formula = "";
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

	}
}